import java.util.HashMap;
import java.util.Map;

/**
 * 20250307-day1
 */
//No1:两数之和
//https://leetcode.cn/problems/two-sum/?envType=study-plan-v2&envId=top-100-liked
public class No1 {
    public static void main(String[] args) {
        //
    }
}

class SolutionNo1 {

    //public int[] twoSum1——哈希表
    public int[] twoSum1(int[] nums, int target) {
        Map<Integer, Integer> map = new HashMap<Integer, Integer>();
        for(int i = 0; i < nums.length; i++){
            if(map.containsKey(target - nums[i])){//找到了
                return new int[]{map.get(target - nums[i]), i};
            }else{
                map.put(nums[i], i);
            }
        }
        return null;
    }

    //public int[] twoSum——两层for
    public int[] twoSum(int[] nums, int target) {
        int[] res = new int[2];
        for(int i = 0; i < nums.length; i++){
            for(int j = i + 1; j < nums.length; j++){
                if(nums[i] + nums[j] == target){
                    res[0] = i;
                    res[1] = j;
                    break;
                }
            }
        }
        return res;
    }
}